package com.ljh.bigevent.controller;

import com.ljh.bigevent.pojo.Category;
import com.ljh.bigevent.pojo.Result;
import com.ljh.bigevent.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Tag(name="分类模块")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
        @Operation(summary = "添加分类接口")
    public Result add(@RequestBody @Validated(Category.Add.class) Category category) {
        return categoryService.addCategory(category);
    }

    @GetMapping
        @Operation(summary = "获取分类列表接口")
    public Result<List<Category>> list() {
        return categoryService.getCategoryList();
    }

    @GetMapping("/detail")
        @Operation(summary = "根据id查询接口")
    public Result<Category> detail(@RequestParam Integer id) {
        return categoryService.getCategoryById(id);
    }

    @PutMapping
        @Operation(summary = "更新分类接口")
    public Result update(@RequestBody @Validated(Category.Update.class) Category category) {
        return categoryService.updateCategory(category);
    }

    @PutMapping("/delete")
        @Operation(summary = "删除分类接口")
    public Result delete(@RequestParam Integer id) {
        return categoryService.deleteCategory(id);
    }

    @GetMapping("/findByDeleted")
        @Operation(summary = "批量删除接口")
    public Result<List<Category>> findByDeleted() {
        return categoryService.getNonDeletedCategories();
    }
}